#pragma once

#include <QFrame>
#include <QLineEdit>

#include "widgets.h"

class SClickedEdit : public QLineEdit {
  Q_OBJECT
 public:
  SClickedEdit();
  explicit SClickedEdit(QWidget* pParent = nullptr, int id = 0)
      : QLineEdit(pParent), m_id(id) {}

 Q_SIGNALS:
  void clicked(int);

 protected Q_SLOTS:
  virtual void mousePressEvent(QMouseEvent* event) override {
    QLineEdit::mousePressEvent(event);
    if (!isReadOnly()) return;
    emit clicked(m_id);
  }

 private:
  int m_id = 0;
};

class QPushButton;
class DualCalendars;
class S_WIDGETS_EXPORT SFilterTermRange : public QFrame {
  Q_OBJECT
 public:
  SFilterTermRange(QWidget* p);

 public:
  void clear();
  bool getYearDayMode() { return m_bYearDayMode; };
  void getTermRange(QString& strStart, QString& strEnd, bool& bYearDayMode);

 protected:
  void setupUI();

 Q_SIGNALS:
  void changed();

 protected Q_SLOTS:
  void toUpper(const QString& str);
  void onEditClick(int id);
  void onBtnSwitchClick();
  void onCalendarSelected(int);
  void onFilterButtonClick();

 protected:
  SClickedEdit* m_edtLeft = nullptr;
  SClickedEdit* m_edtRight = nullptr;
  QPushButton* m_btnSwitch = nullptr;
  QPushButton* m_btnFilter = nullptr;
  DualCalendars* m_calDate = nullptr;

  bool m_bYearDayMode = true;
  bool m_bLeftCaleValid = true;
  int m_dateStart = 0;
  int m_dateEnd = 0;

  QString m_strTermStart, m_strTermEnd;

  QString m_strStyleYearDate, m_strStyleCalendar;
};
